<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="发货单号" prop="cdlcode">
        <el-input   style="width:150px;"
          v-model="queryParams.cdlcode"
          placeholder="请输入发货单号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发货日期" prop="ddate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.ddateRange"
          type="daterange"
         :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="客户编码" prop="ccuscode">
        <el-input   style="width:150px;"
          v-model="queryParams.ccuscode"
          placeholder="请输入客户编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="客户名称" prop="ccusname">
        <el-input    style="width:150px;"
          v-model="queryParams.ccusname"
          placeholder="请输入客户名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="收货地址" prop="cshipaddress">
        <el-input    style="width:150px;"
          v-model="queryParams.cshipaddress"
          placeholder="请输入收货地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"/>
      </el-form-item>

      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:DispatchList:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:DispatchList:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:DispatchList:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:DispatchList:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="DispatchListList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="30" align="center" />
      <el-table-column label="dlid" align="center" prop="dlid"  v-if="false" />
      <el-table-column label="发货单号" align="center"  width="130" prop="cdlcode">
        <template #default="scope">
          <el-link
            type="primary"
            :underline="false"
            @click="handleUpdate(scope.row)"
            style="cursor: pointer; font-weight: 500;"
            class="dispatch-link"
          >
            {{ scope.row.cdlcode }}
          </el-link>
        </template>
      </el-table-column>
      <el-table-column label="" align="center" prop="cvouchtype"  v-if="false"/>
      <el-table-column label="业务类型" align="center" prop="cstcode"  v-if="false" />
      <el-table-column label="日期" align="center" prop="ddate" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ddate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="cdepcode" align="center" prop="cdepcode"  v-if="false"/>
      <el-table-column label="cpersoncode" align="center" prop="cpersoncode"  v-if="false" />
      <el-table-column label="" align="center" prop="sbvid"  v-if="false"  />
      <el-table-column label="" align="center" prop="csbvcode"  v-if="false"/>
      <el-table-column label="" align="center" prop="csocode"  v-if="false"/>
      <el-table-column label="客户编码" align="center" prop="ccuscode"  width="100" />
      <el-table-column label="客户名称" align="center" prop="ccusname"  width="250" show-overflow-tooltip />
      <el-table-column label="联系人" align="center" prop="ccusperson" />
      <el-table-column label="" align="center" prop="cpaycode"  v-if="false" />
      <el-table-column label="" align="center" prop="csccode"  v-if="false" />
      <el-table-column label="收货地址"  width="280" align="center"    prop="cshipaddress"  show-overflow-tooltip  />
      <el-table-column label="" align="center" prop="cexchName"  v-if="false"/>
      <el-table-column label="" align="center" prop="iexchrate"  v-if="false" />
      <el-table-column label="" align="center" prop="itaxrate"  v-if="false" />
      <el-table-column label="" align="center" prop="bfirst"   v-if="false"/>
      <el-table-column label="" align="center" prop="breturnflag" v-if="false"/>
      <el-table-column label="" align="center" prop="bsettleall"  v-if="false"/>
      <el-table-column label="备注"   width="300" align="center" prop="cmemo" show-overflow-tooltip />
      <el-table-column label="" align="center" prop="csaleout"  v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine1"  v-if="false" />
      <el-table-column label="" align="center" prop="cdefine2"  v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine3"  v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine4"   v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine5" v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine6"   v-if="false" />
      <el-table-column label="" align="center" prop="cdefine7" v-if="false" />
      <el-table-column label="" align="center" prop="cdefine8" v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine9" v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine10" v-if="false"/>
      <el-table-column label="课题号" align="center" prop="cdefine11"   show-overflow-tooltip   />

      <el-table-column label="修改人" align="center" prop="cmodifier" />
      <el-table-column label="审核人" align="center" prop="cverifier" />
      <el-table-column label="" align="center" prop="inetlock"  v-if="false"/>
      <el-table-column label="" align="center" prop="isale"  v-if="false"/>
      <el-table-column label="" align="center" prop="ivtid" v-if="false"/>
<!--      <el-table-column label="" align="center" prop="ufts" width="180"/>-->
      <el-table-column label="" align="center" prop="cbustype"  v-if="false" />
      <el-table-column label="" align="center" prop="ccloser"  v-if="false"/>
      <el-table-column label="" align="center" prop="caccounter"   v-if="false" />
      <el-table-column label="" align="center" prop="ccrechpname"   v-if="false"/>

      <el-table-column label="" align="center" prop="cdefine12"  v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine13"   v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine14"  v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine15"   v-if="false"/>
      <el-table-column label="" align="center" prop="cdefine16"  v-if="false"/>
      <el-table-column label="" align="center" prop="biafirst"   v-if="false"/>
      <el-table-column label="" align="center" prop="ioutgolden"  v-if="false"/>
      <el-table-column label="" align="center" prop="cgatheringplan"  v-if="false" />
      <el-table-column label="" align="center" prop="dcreditstart" width="180"   v-if="false" />
      <el-table-column label="" align="center" prop="dgatheringdate" width="180"  v-if="false" />
      <el-table-column label="" align="center" prop="icreditdays"  v-if="false" />
      <el-table-column label="" align="center" prop="bcredit"   v-if="false"/>
      <el-table-column label="" align="center" prop="caddcode"   v-if="false"/>
      <el-table-column label="" align="center" prop="iverifystate"   v-if="false"/>
      <el-table-column label="" align="center" prop="ireturncount"  v-if="false" />
      <el-table-column label="" align="center" prop="iswfcontrolled"  v-if="false"/>
      <el-table-column label="" align="center" prop="icreditstate"  v-if="false" />
      <el-table-column label="" align="center" prop="barfirst"  v-if="false"/>
      <el-table-column label="" align="center" prop="dmoddate" width="180"  v-if="false" />
      <el-table-column label="" align="center" prop="dverifydate" width="180"  v-if="false" />
      <el-table-column label="" align="center" prop="dcreatesystime" width="180"  v-if="false"/>
      <el-table-column label="" align="center" prop="dverifysystime" width="180"   v-if="false" />
      <el-table-column label="" align="center" prop="dmodifysystime" width="180"  v-if="false"/>
      <el-table-column label="" align="center" prop="csvouchtype"  v-if="false"/>
      <el-table-column label="" align="center" prop="iflowid" v-if="false"/>
      <el-table-column label="" align="center" prop="bsigncreate" v-if="false"/>
      <el-table-column label="" align="center" prop="bcashsale" v-if="false"/>
      <el-table-column label="" align="center" prop="cgathingcode" v-if="false" />
      <el-table-column label="" align="center" prop="cchanger"  v-if="false"/>
      <el-table-column label="" align="center" prop="cchangememo"  v-if="false" />
      <el-table-column label="" align="center" prop="outid"  v-if="false"/>
      <el-table-column label="" align="center" prop="bmustbook" v-if="false"/>
      <el-table-column label="" align="center" prop="cbookdepcode"  v-if="false"/>
      <el-table-column label="" align="center" prop="cbooktype" v-if="false"/>
      <el-table-column label="" align="center" prop="bsaused"  v-if="false" />
      <el-table-column label="" align="center" prop="bneedbill" v-if="false"/>
      <el-table-column label="" align="center" prop="baccswitchflag" v-if="false"/>
      <el-table-column label="" align="center" prop="iprintcount" v-if="false"/>
      <el-table-column label="" align="center" prop="ccuspersoncode" v-if="false"/>
      <el-table-column label="" align="center" prop="csourcecode" v-if="false"/>
      <el-table-column label="" align="center" prop="bsaleoutcreatebill"  v-if="false"/>
      <el-table-column label="" align="center" prop="csysbarcode"  v-if="false"/>
      <el-table-column label="" align="center" prop="ccurrentauditor" v-if="false"/>
      <el-table-column label="" align="center" prop="csscode" v-if="false"/>
      <el-table-column label="" align="center" prop="cinvoicecompany" v-if="false"/>
      <el-table-column label="" align="center" prop="febweight" v-if="false"/>
      <el-table-column label="" align="center" prop="cebweightunit" v-if="false"/>
      <el-table-column label="" align="center" prop="cebexpresscode" v-if="false"/>
      <el-table-column label="" align="center" prop="iebexpresscoid" v-if="false"/>
      <el-table-column label="" align="center" prop="separateid" v-if="false"/>
      <el-table-column label="" align="center" prop="bnottogoldtax" v-if="false"/>
      <el-table-column label="" align="center" prop="cebtrnumber" v-if="false"/>
      <el-table-column label="" align="center" prop="cebbuyer" v-if="false"/>
      <el-table-column label="" align="center" prop="cebbuyernote" v-if="false"/>
      <el-table-column label="" align="center" prop="ccontactname" v-if="false"/>
      <el-table-column label="" align="center" prop="cebprovince" v-if="false"/>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改DispatchList对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="98%" append-to-body v-loading="dialogLoading">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row :gutter="3">
          <el-col :span="4">
        <el-form-item label="发货单号" prop="cdlcode">
          <el-input v-model="form.cdlcode"  readonly />
        </el-form-item>
          </el-col>
          <el-col :span="4">
        <el-form-item label="日期" prop="ddate">
          <el-date-picker clearable size="small"    v-model="form.ddate"
            type="date"        value-format="yyyy-MM-dd"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
         </el-col>
          <el-col :span="4">
          <el-form-item label="客户编码" prop="ccuscode">
            <el-input v-model="form.ccuscode" placeholder="请输入客户编码" >
              <el-button slot="append" icon="el-icon-search" @click="showCustomerDialog"></el-button>
            </el-input>
          </el-form-item>
          </el-col>
          <el-col :span="8">
          <el-form-item label="客户名称" prop="ccusname">
            <el-input v-model="form.ccusname" placeholder="请输入"  readonly />
          </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="课题号" prop="cdefine11">
              <el-input v-model="form.cdefine11" placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="5">
          <el-col :span="4">
            <el-form-item label="联系人" prop="ccusperson">
              <el-input v-model="form.ccusperson" placeholder="请输入" >
                <el-button slot="append" icon="el-icon-search" @click="showContactDialog"></el-button>
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="联系手机" prop="cmobilephone"  >
              <el-input v-model="form.cmobilephone"  readonly/>
            </el-form-item>
            <el-form-item label="" prop="ccuspersoncode"  hidden="hidden">
              <el-input v-model="form.ccuspersoncode"   />
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="收货地址" prop="cshipaddress">
              <el-input v-model="form.cshipaddress" placeholder="请输入收货地址" >
                <el-button slot="append" icon="el-icon-search" @click="showAddressDialog"></el-button>
              </el-input>
            </el-form-item>
          </el-col>


            <el-form-item label="收货地址编码" prop="caddcode" hidden="hidden">
              <el-input v-model="form.caddcode" placeholder="" />
            </el-form-item>


        </el-row   >
          <el-row  :gutter="5">
            <el-col :span="8">
              <el-form-item label="备注" prop="cmemo"  >
                <el-input v-model="form.cmemo" placeholder="请输入备注" />
              </el-form-item>
            </el-col>

          <el-col :span="4">
            <el-form-item label="填制人" prop="cmaker">
              <el-input v-model="form.cmaker" placeholder="请输入"  readonly />
            </el-form-item>
          </el-col>

          <el-col  :span="4">
            <el-form-item label="审核人" prop="cverifier">
              <el-input v-model="form.cverifier"   readonly />
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="" prop="dlid"  hidden="hidden">
          <el-input v-model="form.dlid" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cvouchtype"  hidden="hidden" >
          <el-input v-model="form.cvouchtype" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="cstcode"   hidden="hidden">
          <el-input v-model="form.cstcode" placeholder="请输入"    />
        </el-form-item>

        <el-form-item label="" prop="crdcode"  hidden="hidden">
          <el-input v-model="form.crdcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdepcode" hidden="hidden">
          <el-input v-model="form.cdepcode" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="cpersoncode"  hidden="hidden">
          <el-input v-model="form.cpersoncode" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="sbvid"  hidden="hidden">
          <el-input v-model="form.sbvid" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="csbvcode"  hidden="hidden">
          <el-input v-model="form.csbvcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="csocode" hidden="hidden">
          <el-input v-model="form.csocode" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="" prop="cpaycode"  hidden="hidden">
          <el-input v-model="form.cpaycode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="csccode" hidden="hidden">
          <el-input v-model="form.csccode" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="" prop="cexchName"   hidden="hidden">
          <el-input v-model="form.cexchName" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="iexchrate"  hidden="hidden">
          <el-input v-model="form.iexchrate" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="itaxrate"  hidden="hidden">
          <el-input v-model="form.itaxrate" placeholder="请输入"    />
        </el-form-item>
        <el-form-item label="" prop="bfirst"  hidden="hidden">
          <el-input v-model="form.bfirst" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="breturnflag"  hidden="hidden">
          <el-input v-model="form.breturnflag" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="bsettleall"  hidden="hidden">
          <el-input v-model="form.bsettleall" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="csaleout" hidden="hidden">
          <el-input v-model="form.csaleout" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="cdefine1" hidden="hidden">
          <el-input v-model="form.cdefine1" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine2"  hidden="hidden">
          <el-input v-model="form.cdefine2" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine3" hidden="hidden" >
          <el-input v-model="form.cdefine3"    />
        </el-form-item>
        <el-form-item label="" prop="cdefine4"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.cdefine4"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="联系人ID" prop="cdefine5"  hidden="hidden">
          <el-input v-model="form.cdefine5"  />
        </el-form-item>

        <el-form-item label="" prop="cdefine6"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.cdefine6"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="cdefine7"  hidden="hidden">
          <el-input v-model="form.cdefine7" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine8" hidden="hidden">
          <el-input v-model="form.cdefine8" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine9"  hidden="hidden">
          <el-input v-model="form.cdefine9" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine10"  hidden="hidden">
          <el-input v-model="form.cdefine10" placeholder="请输入" />
        </el-form-item >
        <el-form-item label="" prop="inetlock"  hidden="hidden">
          <el-input v-model="form.inetlock" placeholder="请输入"  />
        </el-form-item >
        <el-form-item label="" prop="isale"  hidden="hidden">
          <el-input v-model="form.isale" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="ivtid" hidden="hidden">
          <el-input v-model="form.ivtid" placeholder="请输入"  />
        </el-form-item>
<!--        <el-form-item label="" prop="ufts"/>      -->
        <el-form-item label="业务类型" prop="cbustype"   hidden="hidden">
          <el-input v-model="form.cbustype" placeholder="请选择"  />
        </el-form-item>
        <el-form-item label="" prop="ccloser"  hidden="hidden">
          <el-input v-model="form.ccloser" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="caccounter" hidden="hidden">
          <el-input v-model="form.caccounter" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="ccrechpname" hidden="hidden">
          <el-input v-model="form.ccrechpname" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine12"  hidden="hidden">
          <el-input v-model="form.cdefine12" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine13"  hidden="hidden">
          <el-input v-model="form.cdefine13" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="cdefine14"  hidden="hidden">
          <el-input v-model="form.cdefine14" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine15"  hidden="hidden">
          <el-input v-model="form.cdefine15" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cdefine16"  hidden="hidden">
          <el-input v-model="form.cdefine16" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="biafirst"  hidden="hidden">
          <el-input v-model="form.biafirst" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="ioutgolden"  hidden="hidden">
          <el-input v-model="form.ioutgolden" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="cgatheringplan"  hidden="hidden">
          <el-input v-model="form.cgatheringplan" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="dcreditstart"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dcreditstart"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="dgatheringdate" hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dgatheringdate"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="icreditdays"  hidden="hidden">
          <el-input v-model="form.icreditdays" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bcredit" hidden="hidden">
          <el-input v-model="form.bcredit" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="iverifystate" hidden="hidden">
          <el-input v-model="form.iverifystate" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="ireturncount" hidden="hidden">
          <el-input v-model="form.ireturncount" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="iswfcontrolled"  hidden="hidden">
          <el-input v-model="form.iswfcontrolled" placeholder="请输入"    />
        </el-form-item>
        <el-form-item label="" prop="icreditstate"  hidden="hidden">
          <el-input v-model="form.icreditstate" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="barfirst"  hidden="hidden">
          <el-input v-model="form.barfirst" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="cmodifier"  hidden="hidden">
          <el-input v-model="form.cmodifier" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="dmoddate"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dmoddate"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="dverifydate"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dverifydate"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="dcreatesystime"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dcreatesystime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="dverifysystime"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dverifysystime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="dmodifysystime"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dmodifysystime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="csvouchtype"  hidden="hidden">
             <el-input v-model="form.csvouchtype" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="iflowid"  hidden="hidden">
          <el-input v-model="form.iflowid" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bsigncreate"  hidden="hidden">
          <el-input v-model="form.bsigncreate" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bcashsale"  hidden="hidden">
          <el-input v-model="form.bcashsale" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cgathingcode"  hidden="hidden">
          <el-input v-model="form.cgathingcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cchanger"  hidden="hidden">
          <el-input v-model="form.cchanger" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cchangememo"  hidden="hidden">
          <el-input v-model="form.cchangememo" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="outid"  hidden="hidden">
          <el-input v-model="form.outid" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bmustbook"  hidden="hidden">
          <el-input v-model="form.bmustbook" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cbookdepcode"  hidden="hidden">
          <el-input v-model="form.cbookdepcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cbooktype"  hidden="hidden">
          <el-select v-model="form.cbooktype" placeholder="请选择"/>
        </el-form-item>
        <el-form-item label="" prop="bsaused"  hidden="hidden">
          <el-input v-model="form.bsaused" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bneedbill"  hidden="hidden">
          <el-input v-model="form.bneedbill" placeholder="请输入"  />
        </el-form-item>
        <el-form-item label="" prop="baccswitchflag"  hidden="hidden">
          <el-input v-model="form.baccswitchflag" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="iprintcount"  hidden="hidden">
          <el-input v-model="form.iprintcount" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="" prop="csourcecode"  hidden="hidden">
          <el-input v-model="form.csourcecode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bsaleoutcreatebill"  hidden="hidden">
          <el-input v-model="form.bsaleoutcreatebill" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="csysbarcode"  hidden="hidden">
          <el-input v-model="form.csysbarcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="ccurrentauditor"  hidden="hidden">
          <el-input v-model="form.ccurrentauditor" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="csscode"   hidden="hidden">
          <el-input v-model="form.csscode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cinvoicecompany"  hidden="hidden">
          <el-input v-model="form.cinvoicecompany" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="febweight"   hidden="hidden">
          <el-input v-model="form.febweight" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebweightunit"  hidden="hidden">
          <el-input v-model="form.cebweightunit" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebexpresscode"  hidden="hidden">
          <el-input v-model="form.cebexpresscode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="iebexpresscoid"  hidden="hidden">
          <el-input v-model="form.iebexpresscoid" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="separateid"   hidden="hidden">
          <el-input v-model="form.separateid" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="bnottogoldtax"  hidden="hidden">
          <el-input v-model="form.bnottogoldtax" placeholder="请输入"   />
        </el-form-item>
        <el-form-item label="" prop="cebtrnumber"  hidden="hidden">
          <el-input v-model="form.cebtrnumber" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebbuyer"  hidden="hidden">
          <el-input v-model="form.cebbuyer" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebbuyernote"   hidden="hidden">
          <el-input v-model="form.cebbuyernote" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="ccontactname"  hidden="hidden">
          <el-input v-model="form.ccontactname" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebprovince"  hidden="hidden">
          <el-input v-model="form.cebprovince" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebcity"   hidden="hidden">
          <el-input v-model="form.cebcity" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cebdistrict"   hidden="hidden">
          <el-input v-model="form.cebdistrict" placeholder="请输入" />
        </el-form-item>


        <el-form-item label="" prop="cinvoicecusname"  hidden="hidden">
          <el-input v-model="form.cinvoicecusname" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cweighter"  hidden="hidden">
          <el-input v-model="form.cweighter" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="dweighttime"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dweighttime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="cpickvouchcode"  hidden="hidden">
          <el-input v-model="form.cpickvouchcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cgcroutecode"  hidden="hidden">
          <el-input v-model="form.cgcroutecode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="cbcode"   hidden="hidden">
          <el-input v-model="form.cbcode" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="" prop="dhclosedate"   hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dhclosedate"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="" prop="dhclosesystime"  hidden="hidden">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.dhclosesystime"
            type="date"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择">
          </el-date-picker>
        </el-form-item>

        <DispatchLists ref="DispatchLists"  :detailResponse="detailResponse"></DispatchLists>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 客户选择对话框 -->
    <el-dialog :visible.sync="customerDialogVisible" title="选择客户" width="90%" top="5vh">
      <Customer  @row-dblclick="selectCustomerFromDialog"  :isDialog="true" />
    </el-dialog>

    <el-dialog :visible.sync="contactDialogVisible" title="选择联系人" width="90%" top="5vh">
      <CustomerContact  @dbclick="selectContactFromDialog"  :ccuscode="form.ccuscode"  :isDialog="true" />
    </el-dialog>

    <el-dialog :visible.sync="addressDialogVisible" title="选择收货地址" width="90%" top="5vh">
      <CustomerAddress  @dbclick="selectAddresstFromDialog"  :ccuscode="form.ccuscode"  :isDialog="true" />
    </el-dialog>
  </div>
</template>

<script>
import { listDispatchList, getDispatchList, delDispatchList, addDispatchList, updateDispatchList, exportDispatchList,getCdlcode } from "@/api/business/DispatchList";
import Customer from "@/views/business/Customer/index.vue";
import  CustomerContact  from "@/views/business/contact/index.vue";
import  CustomerAddress  from  "@/views/business/address/index.vue";
import DispatchLists      from   "@/views/business/DispatchLists/index.vue";
import store from "@/store";
import {listDispatchLists} from "@/api/business/DispatchLists";

export default {
  name: "DispatchList",
  components: {
    Customer,CustomerContact,CustomerAddress,DispatchLists
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 对话框加载状态
      dialogLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      customerDialogVisible: false,
      contactDialogVisible: false,
      addressDialogVisible: false,
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      // DispatchList表格数据
      detailResponse: {},
      DispatchListList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dlid: null,
        cdlcode: null,
         cstcode: null,
        ddate: null,
        crdcode: null,
        cdepcode: null,
        cpersoncode: null,
        csbvcode: null,
        csocode: null,
        ccuscode: null,
        cpaycode: null,
        csccode: null,
        cshipaddress: null,
        cverifier: null,
        cmaker: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
         ddate: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        cdepcode: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        cexchName: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        iexchrate: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        bfirst: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        breturnflag: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        bsettleall: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        ivtid: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询DispatchList列表 */
    getList() {
      this.loading = true;
      listDispatchList(this.queryParams).then(response => {
        this.DispatchListList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(error => {
        console.error('获取订单列表失败:', error);
        this.$message.error('获取订单列表失败，请重试');
        this.loading = false;
      });
    }, getDetailList(dlid) {
      this.dialogLoading = true;
      var   param =  {
        pageNum: 1,
          pageSize: 1000,
          dlid: dlid,
      };
      listDispatchLists(param).then(response => {
        debugger;
        this.detailResponse = response;
        this.$nextTick(() => {
          if (this.$refs.DispatchLists) {
            this.$refs.DispatchLists.setData();
          }
        });
        this.dialogLoading = false;
      }).catch(error => {
        console.error('获取订单详情失败:', error);
        this.$message.error('获取订单详情失败，请重试');
        this.dialogLoading = false;
      });
    },
    
    // 获取详情数据的方法，不管理loading状态
    getDetailListData(dlid) {
      var param = {
        pageNum: 1,
        pageSize: 1000,
        dlid: dlid,
      };
      return listDispatchLists(param);
    },



    selectCustomerFromDialog(row) {
         this.form.ccuscode = row.ccuscode;
         this.form.ccusname=row.ccusname;
        this.customerDialogVisible = false;
    },selectContactFromDialog(row){
        this.form.cmobilephone = row.phone;
         this.form.ccuspersoncode=row.id;
         this.form.ccusperson=row.person;
         this.contactDialogVisible = false;
    },selectAddresstFromDialog(row){
      this.form.cshipaddress=row.areafullname+' '+ row.address;
      this.form.caddcode=row.id;
      this.addressDialogVisible = false;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    }, showCustomerDialog() {
      this.customerDialogVisible = true;
    },showContactDialog(){
      if(this.form.ccuscode==null ||this.form.ccuscode==''){
        this.$msgbox.alert("请先选择客户");
        return;
      }
      this.contactDialogVisible=true;
    },showAddressDialog(){
      if(this.form.ccuscode==null ||this.form.ccuscode==''){
        this.$msgbox.alert("请先选择客户");
        return;
      }
      this.addressDialogVisible=true;
    },
    // 表单重置
    reset() {
      this.form = {
        dlid: null,
        cdlcode: null,
         cstcode: null,
        ddate: null,
        crdcode: null,
        cdepcode: null,
        cpersoncode: null,
        csbvcode: null,
        csocode: null,
        ccuscode: null,
        cpaycode: null,
        csccode: null,
        cshipaddress: null,
        cexchName: null,
        iexchrate: null,
        itaxrate: null,
        bfirst: null,
        breturnflag: null,
        bsettleall: null,
        cmemo: null,
        csaleout: null,
        cdefine1: null,
        cdefine2: null,
        cdefine3: null,
        cdefine4: null,
        cdefine5: null,
        cdefine6: null,
        cdefine7: null,
        cdefine8: null,
        cdefine9: null,
        cdefine10: null,
        cverifier: null,
        cmaker: null,
        inetlock: null,
        isale: null,
        ccusname: null,
        ivtid: null,
        cbustype: null,
        ccloser: null,
        caccounter: null,
        ccrechpname: null,
        cdefine11: null,
        cdefine12: null,
        cdefine13: null,
        cdefine14: null,
        cdefine15: null,
        cdefine16: null,
        biafirst: null,
        ioutgolden: null,
        cgatheringplan: null,
        dcreditstart: null,
        dgatheringdate: null,
        icreditdays: null,
        bcredit: null,
        caddcode: null,
        iverifystate: null,
        ireturncount: null,
        iswfcontrolled: null,
        icreditstate: null,
        barfirst: null,
        cmodifier: null,
        dmoddate: null,
        dverifydate: null,
        ccusperson: null,
        dcreatesystime: null,
        dverifysystime: null,
        dmodifysystime: null,
        csvouchtype: null,
        iflowid: null,
        bsigncreate: null,
        bcashsale: null,
        cgathingcode: null,
        cchanger: null,
        cchangememo: null,
        outid: null,
        bmustbook: null,
        cbookdepcode: null,
        cbooktype: null,
        bsaused: null,
        bneedbill: null,
        baccswitchflag: null,
        iprintcount: null,
        ccuspersoncode: null,
        csourcecode: null,
        bsaleoutcreatebill: null,
        csysbarcode: null,
        ccurrentauditor: null,
        csscode: null,
        cinvoicecompany: null,
        febweight: null,
        cebweightunit: null,
        cebexpresscode: null,
        iebexpresscoid: null,
        separateid: null,
        bnottogoldtax: null,
        cebtrnumber: null,
        cebbuyer: null,
        cebbuyernote: null,
        ccontactname: null,
        cebprovince: null,
        cebcity: null,
        cebdistrict: null,
        cmobilephone: null,
        cinvoicecusname: null,
        cweighter: null,
        dweighttime: null,
        cpickvouchcode: null,
        cgcroutecode: null,
        cbcode: null,
        dhclosedate: null,
        dhclosesystime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      debugger;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.dlid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "选购商品";
      if (!this.form.ddate) {
        this.form.ddate = this.getToday();
      }
      getCdlcode().then(response => {
        this.form.cdlcode = response.msg;
      });
      this.form.cmaker = store.getters.name;
      this.form.cvouchtype = "05";
      this.form.cstcode = "XX";
      this.form.cdepcode = "01"
      this.form.cpersoncode = "054";
      this.form.sbvid = 0;
      this.form.cexchName = "人民币";
      this.form.iexchrate = 1;
      this.form.itaxrate = 13;
      this.form.bfirst = 0;
      this.form.breturnflag = 0;
      this.form.bsettleall = 0;
      this.form.inetlock = 0;
      this.form.isale = 0;
      this.form.ivtid = 131468;
      this.form.cbustype = "普通销售";
      this.form.biafirst = 0;
      this.form.ioutgolden = 0;
      this.form.bcredit = 0;
      this.form.iverifystate = 0;
      this.form.ireturncount = 0;
      this.form.iswfcontrolled = 0;
      this.form.barfirst = 0;
      this.form.bneedbill = 0;
      this.form.bsaleoutcreatebill = 0;
      this.form.bnottogoldtax = 0;
      // 等待DOM更新完成后，清空子组件数据
      this.$nextTick(() => {
        if (this.$refs.DispatchLists) {
          this.$refs.DispatchLists.clearData();
        }
      });
    },  getToday() {
      // 返回 yyyy-MM-dd 格式
      const d = new Date();
      const month = (d.getMonth() + 1).toString().padStart(2, '0');
      const day = d.getDate().toString().padStart(2, '0');
      return `${d.getFullYear()}-${month}-${day}`;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const dlid = row.dlid || this.ids
      debugger;
      this.dialogLoading = true;
      
      // 并行获取订单信息和详情
      Promise.all([
        getDispatchList(dlid),
        this.getDetailListData(dlid)
      ]).then(([dispatchResponse, detailResponse]) => {
        debugger;
        this.form = dispatchResponse.data;
        this.detailResponse = detailResponse;
        this.open = true;
        this.title = "修改订单";
        
        // 等待对话框打开后再设置子组件数据
        this.$nextTick(() => {
          if (this.$refs.DispatchLists) {
            this.$refs.DispatchLists.setData();
          }
          this.dialogLoading = false;
        });
      }).catch(error => {
        debugger;
        console.error('获取订单信息失败:', error);
        this.$message.error('获取订单信息失败，请重试');
        this.dialogLoading = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
       // 获取组件DispatchLists中的数据
          const child = this.$refs.DispatchLists;
          if (child) {
            const list = child.getData();
            console.log("获取到的数据:", list);
            if (!list || list.length === 0) {
              this.$msgbox.alert("请添加订单明细", "提示");
              return;
            }
            this.form.dispatchLists = list;
          } else {
            console.error("无法获取子组件数据，子组件引用:", child);
            this.$msgbox.alert("无法获取订单明细数据", "错误");
            return;
          }
          if (this.form.dlid != null) {
            updateDispatchList(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDispatchList(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dlids = row.dlid || this.ids;
      this.$confirm('是否确认删除DispatchList编号为"' + dlids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delDispatchList(dlids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有DispatchList数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDispatchList(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>

<style scoped>
.dispatch-link {
  transition: all 0.3s ease;
}

.dispatch-link:hover {
  color: #409EFF !important;
  transform: scale(1.05);
  text-decoration: underline;
}

.dispatch-link:active {
  transform: scale(0.98);
}
</style>
